#include <REGX52.H>
#include "Timer0.h"
#include "Key.h"
#include "INTRINS.H"

unsigned char LEDNum,LEDMode,Speed;
void main()
{
	Timer0_Init();          //定时器0开始运行
	while(1)
	{
		LEDNum=Key();
		if(LEDNum)
		{
			if(LEDNum==1)
				LEDMode=1;
			else if(LEDNum==2)
				LEDMode=2;
			else if(LEDNum==3)
				LEDMode=3;
			else if(LEDNum==4)
			{
				Speed++;     //速度调节
				Speed%=3;
			}
		}
	}
	return;
}

unsigned int time[]={1000,500,250};

//定时到转到中断系统里来运行，运行完再回原位置
void Timer0_Routine(void)   interrupt 1
{
	static unsigned int T0cnt;  //静态变量
	TL0 = 0x66;				//设置定时初始值 
	TH0 = 0xFC;				//设置定时初始值 
	T0cnt++;
	if(T0cnt>=time[Speed])       //定时
	{
		T0cnt=0;
		//启动开关
		if(LEDMode == 1)
		{
			P2=0xFC;
		}
		//LED右移流水灯
		else if(LEDMode == 2)
		{
			P2=_crol_(P2,1);     //循环左移
		}
		//LED左移流水灯
		else if(LEDMode == 3)
		{
			P2=_cror_(P2,1);     //循环右移
		}
	}
}

